#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int main()
{
	vector<int> mp;
	int n, m;cin >> n >> m;int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		int x;cin >> x;
		mp.push_back(x);
	}
	sort(mp.begin(), mp.end());
	for (auto v : mp)
	{
		int ret = v + m;
		auto p1 = lower_bound(mp.begin(), mp.end(), ret);
		auto p2 = upper_bound(mp.begin(), mp.end(), ret);
		int len = p2 - p1;
		sum += len;
	}
	cout << sum << endl;
	return 0;
}